package com.pat.java.base.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;
import java.util.Vector;

public class UseStream extends Object {
	public static void main(String[] args) {
		Vector<String> v = new Vector<String>();
		v.add("语文");
		v.add("数学");
		v.add("英语");
		try {
			File f = new File("files/temp.txt");
			FileOutputStream fOut = new FileOutputStream(f);
			ObjectOutputStream objOut = new

			ObjectOutputStream(fOut);

			objOut.writeObject(new Date());

			objOut.writeObject(v);
			objOut.close();

			readObj rObj = new readObj();

			rObj.readO();
		} catch (IOException e) {

			System.out.println(e.getMessage());
		}
	}
};

class readObj extends Object {
	public void readO() {
		File f = null;
		try {
			String oldPath = new UseStream().getClass().getClassLoader().getResource("").getPath();
			String newPath = java.net.URLDecoder.decode(oldPath, "utf-8");
			f = new File(newPath+"/temp.txt");

			FileInputStream fIn = new FileInputStream(f);
			ObjectInputStream objIn = new ObjectInputStream(fIn);

			Object ob1 = objIn.readObject();
			System.out.println(ob1);
			Object ob2 = objIn.readObject();
			System.out.println(ob2);
		} catch (IOException e) {
			System.out.println(e.getMessage());
		} catch (ClassNotFoundException e) {
			System.out.println(e.getMessage());
		}finally{
			//f.deleteOnExit();
		}
	}
}
